﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;

namespace DAO
{
    public class MucGiamDAO
    {
        public List<shop_mucgiam> LayDanhSachMucGiam()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var mg = from c in EFashionDB.shop_mucgiams select c;
            return mg.ToList();
        }

        public shop_mucgiam LayMucGiamsTheoMa(int MaMucGiam)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_mucgiam mg = EFashionDB.shop_mucgiams.Single(c => c.MaMucGiam == MaMucGiam);
            return mg;
        }

        public void XoaMucGiam(int MaMucGiam)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var mg = (from c in EFashionDB.shop_mucgiams
                      where c.MaMucGiam == MaMucGiam
                       select c);
            EFashionDB.shop_mucgiams.DeleteAllOnSubmit(mg);
            EFashionDB.SubmitChanges();
        }

        public void CapNhatMucGiam(shop_mucgiam mgLinq)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_mucgiam mg = EFashionDB.shop_mucgiams.Single(c => c.MaMucGiam == mgLinq.MaMucGiam);
            mg.ThangDiem = mgLinq.ThangDiem;
            mg.MucGiam = mgLinq.MucGiam;

            EFashionDB.SubmitChanges();
        }

        public void ThemMucGiam(shop_mucgiam mgLinq)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.shop_mucgiams.InsertOnSubmit(mgLinq);

            EFashionDB.SubmitChanges();
        }

    }
}
